package com.java3_6;

public class Student2 implements Comparable{
    private String name;
    private int age;
    public Student2(){

    }

    public Student2(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public int compareTo(Object o) {
        if(this == o)
            return 0;
        if(o instanceof Student2 o1){
            int value = this.age - o1.age;
            if(value != 0)
                return value;
            return this.name.compareTo(o1.name);
        }
        throw new RuntimeException("类型错误");
    }
}
